package edu.pku.sei.modeler.uml.commands.sequence;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.uml.BasicInteractions.DestructionEvent;
import edu.pku.sei.modeler.model.uml.BasicInteractions.Lifeline;
import edu.pku.sei.modeler.uml.commands.NestedElementDeleteCommand;

public class UMLStopDeleteCommand extends NestedElementDeleteCommand {

	private DestructionEvent oldStopEvent;

	public UMLStopDeleteCommand(MetaNode node, MetaNode fatherNode,
			boolean isDeletedFromDiagram) {
		super(node, fatherNode, isDeletedFromDiagram);
	}

	@Override
	protected void deleteModelElement() {
		Lifeline lifeline = (Lifeline) fatherNode.getModelElement();
		if (this.oldStopEvent != null) {
			lifeline.setIncludedStopEvent(this.oldStopEvent);
		}
	}

	@Override
	protected void undoDeleteModelElement() {
		MetaModelElement modelElement = this.node.getModelElement();
		Lifeline lifeline = (Lifeline) fatherNode.getModelElement();
		this.oldStopEvent = lifeline.getIncludedStopEvent();
		lifeline.setIncludedStopEvent((DestructionEvent) modelElement);
	}

}
